/*
 *  This program is free software; you can redistribute it and/or modify
 *  it under the terms of the GNU Lesser General Public License Version
 *  3 as published by the Free Software Foundation.
 *
 *  This program is distributed in the hope that it will be useful,
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 *  GNU Lesser General Public License for more details.
 *
 *  You should have received a copy of the GNU Lesser General Public
 *  License along with this program; if not, write to the Free Software
 *  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307,
 *  USA.
 */

#include <optra/common/db.h>

using namespace Optra;

class Optra::DBPrivate
{
public:
    DBPrivate(){};

    ~DBPrivate(){
        db.close();
    }

    QSqlDatabase db;
};

DB::DB(const QString& name, QObject *parent) :
    QObject(parent), O_PRIVATE_CREATE(DB)
{
    O_D(DB)
    d->db = QSqlDatabase::addDatabase("QSQLITE", name);
    d->db.setDatabaseName(name);
    d->db.open();
}

DB::~DB()
{
    O_PRIVATE_DELETE;
}

QSqlDatabase DB::db()
{
    O_D(DB)
    return d->db;
}

 QSqlQuery DB::query(const QString& q)
 {
    return QSqlQuery(q, db());
 }
